package cn.edu.leetcode.数组操作;

import java.util.Arrays;

public class 加一 {
    public static int[] plusOne(int[] digits) {
        for (int i = digits.length-1; i >= 0 ; i--) {
            if(digits[i]+1>=10){
                digits[i] = 0;
            }else {
                digits[i]++;
                return digits;
            }
        }
        int[] a = new int[digits.length+1];
        a[0] = 1;
        System.arraycopy(digits, 0, a, 1, digits.length);

        return a;
    }

    public static void main(String[] args) {
        int[] num = {9, 9};
        System.out.println(Arrays.toString(plusOne(num)));
    }
}
